void TexSpace::InitPNGLoader()
{
	PNG_Init(&TexSpace::pngInfo);
}

void TexSpace::DeInitPNGLoader()
{
	PNG_Cleanup(&TexSpace::pngInfo);
}

image_src * TexSpace::ReadPNGFile(const char *filename)
{
	image_src *result = new image_src();

	PNG_LoadFile(&TexSpace::pngInfo,filename);
	PNG_Decode(&TexSpace::pngInfo);

	HBITMAP hBitmap;
	hBitmap = PNG_CreateBitmap(&TexSpace::pngInfo, hWnd, PNG_OUTF_AUTO, false);

	HDC bitmapDC = CreateCompatibleDC(hDC);

	SelectObject(bitmapDC,hBitmap);

	int width = TexSpace::pngInfo.iWidth;
	int height = TexSpace::pngInfo.iHeight;
	int bpp = 3;
	
	if(TexSpace::pngInfo.PNGColorType == 2) 
		bpp = 3;

	DEBUG_LOG(width);
	DEBUG_LOG(height);
	DEBUG_LOG(bpp);

	result->texels = new unsigned char[width*height*bpp];
	result->width = width;
	result->height = height;
	result->bpp = bpp;
	result->comp = 0;
	result->depth = 1;
	result->format = GL_RGB;
	result->internalFormat = bpp;
	result->numMipmaps = 0;
	result->type = GL_UNSIGNED_BYTE;
    result->bpc = 1;

	for(int i=0;i<width;++i)
	{
		for(int j=0;j<height;++j)
		{
			unsigned int c = GetPixel(bitmapDC,i,j);

			int ind = (i*height + j)*bpp;

			if(bpp==3)
			{
				result->texels[ind+0] = rgba_r(c);
				result->texels[ind+1] = rgba_g(c);
				result->texels[ind+2] = rgba_b(c);
			}			
		}
	}

	DeleteObject(bitmapDC);
	ReleaseDC(hWnd,bitmapDC);
	//PNG_CreateBitmap(&TexSpace::pngInfo,hWnd,
	return result;
}